<?php 
	Class Activityprice extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model('model_activity');
			$this->load->model('model_activityprice');
		}	
		
		public function index(){
			if(isset($_GET['activityid'])){
				$data['activity']=$this->model_activity->getdata(intval($_GET['activityid']));
				$data['data']=$this->model_activityprice->getallbyid(intval($_GET['activityid']));
			}
			
			$data['template']='activity/activityprice';
			$this->load->view('layout',$data);	
		}
		
		public function edit(){
			if(isset($_GET['id'])){
				$data['detail']	=$this->model_activityprice->getdata(intval($_GET['id']));				
			}else $data['detail']=NULL;
			
			$data['template']='activity/activityprice_edit';
			$this->load->view('layout',$data);		
		}
		
		public function insert(){
			$data['datefrom']=date("Y-m-d",strtotime($_POST['datefrom']));	
			$data['dateto']=date("Y-m-d",strtotime($_POST['dateto']));	
			$data['pricefor1']=$_POST['pricefor1'];
			$data['pricefor2']=$_POST['pricefor2'];
			$data['pricefor34']=$_POST['pricefor34'];
			$data['pricefor58']=$_POST['pricefor58'];
			$data['pricefor912']=$_POST['pricefor912'];
			$data['pricefor1316']=$_POST['pricefor1316'];
			$data['pricefor16']=$_POST['pricefor16'];
			$data['activityid']=intval($_GET['activityid']);
			$data['status']=$_POST['status'];
            
			$this->model_activityprice->add($data);
			header('Location: '.base_url().'admin/activityprice/index?activityid='.intval($_GET['activityid']));
		}
		
		public function update(){
			if(isset($_GET["id"])){
				$data['datefrom']=date("Y-m-d",strtotime($_POST['datefrom']));	
				$data['dateto']=date("Y-m-d",strtotime($_POST['dateto']));	
				$data['pricefor1']=$_POST['pricefor1'];
				$data['pricefor2']=$_POST['pricefor2'];
				$data['pricefor34']=$_POST['pricefor34'];
				$data['pricefor58']=$_POST['pricefor58'];
				$data['pricefor912']=$_POST['pricefor912'];
				$data['pricefor1316']=$_POST['pricefor1316'];
				$data['pricefor16']=$_POST['pricefor16'];
				$data['activityid']=intval($_GET['activityid']);
				$data['status']=$_POST['status'];
				
				$this->model_activityprice->update($data,intval($_GET['id']));
				header('Location: '.base_url().'admin/activityprice/index?activityid='.intval($_GET['activityid']));
			}	
		}
		
		public function delete(){
			if(isset($_GET["id"])){
                $data = $this->model_activityprice->getdata($_GET['id']);
				$this->model_activityprice->del(intval($_GET['id']));	
				header('Location: '.base_url().'admin/activityprice/index?activityid='.intval($_GET['activityid']));
			}	
		}
		
		public function changestatus(){			
			if(isset($_GET["id"])){		
				$data=$this->model_activityprice->getdata(intval($_GET["id"]));								
				if(count($data)>0){
					if(isset($_GET["status"])){
						$data['status']=intval($_GET['status']);
						$this->model_activityprice->update($data,intval($_GET["id"]));
						header('Location: '.base_url().'admin/activityprice/index?activityid='.intval($_GET['activityid']));
					}
				}
			}
		}
        public function createThumbnail($fileName,$path,$width,$height){
            $this->load->library('image_lib');
            $config['image_library'] = 'gd2';
            $config['source_image'] = 'uploads/'.$path.'/'.$fileName;
            $config['new_image']    = 'uploads/'.$path.'/thumb/'.$fileName;
            $config['create_thumb'] = TRUE;
            $config['maintain_ratio'] = TRUE;
            $config['thumb_marker'] = FALSE;
            $config['width'] = $width;
            $config['height'] = $height;
            $this->image_lib->initialize($config);
            $this->image_lib->resize();
            $this->image_lib->clear();
        }
	}
?>